<?php

class Core_Role extends Zend_Db_Table_Abstract {

    protected $_name = 'db_roles';

    //Get al roles
    public function getAll() {
        $select = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('tu' => 'db_roles'));
        return $this->_fetch($select);
    }

    //Update single role
    public function updateRole($id, $data) {
        $this->_db->update('db_roles', $data, 'id = ' . $id);
    }

    //Delete single role
    public function deleteRole($id) {
        $this->_db->delete('db_roles', 'id = ' . $id);
    }

    //Insert role
    public function setRole($data) {

        $this->_db->insert('db_roles', $data);
        return 1;
    }

    //Get roles by name of role
    public function getRolesByTipo($roleName) {
        $select = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('tu' => 'db_roles'))
                        ->where('tu.role = ? ', $roleName);
        return $this->_fetch($select);
    }

    //Get role by ID
    public function getRoleByID($id) {
        $select = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('tu' => 'db_roles'))
                        ->where('tu.id = ? ', $id);
        return $this->_fetch($select);
    }

}